package org.examples;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;

import io.netty.handler.codec.http.HttpHeaderNames;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;
import reactor.netty.ByteBufFlux;
import reactor.netty.http.client.HttpClient;

import static org.examples.DebugConstants.gwPath;
import static org.examples.DebugConstants.gwRequestData;
import static org.examples.DebugConstants.gwTtsParameter;
import static org.examples.DebugConstants.host;
import static org.examples.DebugConstants.isHttps;

@Slf4j
public class ReactorSendRaw {
  public static void main(final String[] args) throws Exception {
    log.info("ReactorGw.main");
    HttpClient client = HttpClient.create().baseUrl(host);
    if (isHttps()) {
      client = client.secure();
    }
    client
        .headers(headers -> {
          headers.set(HttpHeaderNames.ACCEPT, "audio/ogg;codecs=opus");
        })
        .post()               // Specifies that POST method will be used
        .uri(gwPath())   // Specifies the path

        .send(ByteBufFlux.fromString(Flux.just("Hello")))  // Sends the request body


        .responseContent()    // Receives the response body
                        .aggregate()
                        .asString()
        .log("http-client")
                .block();
//        .blockLast();
  }
}
